<template>
  <el-row type="flex" justify="center" align="middle" class="pageWrapper">
    <el-form ref="form" label-width="80px">
      <el-form-item label="手机">
        <el-input v-model="form.username"></el-input>
      </el-form-item>

      <el-form-item label="密码">
        <el-input v-model="form.password" type="password"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
  </el-row>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    onSubmit() {
      if (!this.form.username || !this.form.password) {
        this.$message.warning("请输入完整信息");
        return;
      }
      this.$axios.post("/login", this.form).then((res) => {
        // console.log(res.data);
        if (res.data.message === "登录成功") {
          this.$message.success("登录成功");
          window.localStorage.setItem("token", res.data.data.token);
          this.$router.push("/");
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    reset() {
      this.form = {
        username: "",
        password: "",
      };
    },
  },
};
</script>

<style lang="less" scoped>
.pageWrapper {
  min-height: 100vh;
  background: #eee;
}
</style>